<?php

namespace SinoPHP\BbdBoss\Api;

use InvalidArgumentException;
use Upfor\UpforPHP\Library\Math;

/**
 * 服务器组与域名关系映射
 */
class ServerGroupAndDomainRelation extends ApiAbstract {

    /**
     * @var \SinoPHP\BbdBoss\Model\CacheSystemRelation
     */
    protected $cacheSystemRelation;

    public function v_1_0_0() {
        $this->cacheSystemRelation = model('CacheSystemRelation');

        $data = array();
        $allServerGroupList = $this->cacheSystemRelation->getAllServerGroupList();
        $groupIds = array_column($allServerGroupList, 'server_group_id');

        $refList = $this->cacheSystemRelation->getDomainListByBindGroup($groupIds);

        foreach ($allServerGroupList as $row) {
            if (!empty($refList[$row['server_group_id']])) {
                $data[$row['server_code']] = array_values(array_unique($refList[$row['server_group_id']]));
            }
        }

        $this->success($data);
    }

}
